library(tidyverse)
library(admiral)
library(lubridate)Clinical Data Journey (Phase 6): Building Our First ADaM Dataset using admiral
Objective
In the previous phase, we completed a metadata-driven SDTM workflow and created standardized SDTM datasets.
SDTM datasets provide a standardized representation of collected clinical trial data. Statistical analysis requires additional variables and derivations such as treatment assignments, analysis dates, and population flags.
ADaM (Analysis Data Model) datasets are analysis-ready datasets derived primarily from SDTM datasets. They are designed to support statistical analysis and maintain traceability from collected data to analysis results.
In this phase, we will use the admiral package to transform an SDTM DM (Demographics) dataset into our first ADaM dataset:
ADSL (Subject-Level Analysis Dataset)
ADSL serves as the foundation dataset for many downstream analysis datasets including:
- ADAE (Adverse Events Analysis Dataset)
- ADVS (Vital Signs Analysis Dataset)
- ADLB (Laboratory Analysis Dataset)
- Efficacy analysis datasets
Load Required Packages
Import SDTM DM Dataset
The SDTM DM dataset contains subject-level information such as demographics, treatment assignment, and study dates.
The SDTM DM dataset already follows CDISC standards. The objective is no longer to standardize collected data, but to derive analysis-ready variables required for statistical analysis.
dm <- read_csv("DM.csv",show_col_types = FALSE,
col_types = cols(
RFSTDTC = col_character(),
RFENDTC = col_character(),
BRTHDTC = col_character()
)
)Remove any empty records if present:
dm <- dm %>%
filter(!is.na(USUBJID))Review the imported dataset:
glimpse(dm)Rows: 8
Columns: 13
$ STUDYID <chr> "ONCO001", "ONCO001", "ONCO001", "ONCO001", "ONCO001", "ONCO00…
$ DOMAIN <chr> "DM", "DM", "DM", "DM", "DM", "DM", "DM", "DM"
$ USUBJID <chr> "ONCO001-SITE001-001", "ONCO001-SITE001-002", "ONCO001-SITE001…
$ SUBJID <dbl> 1, 2, 3, 4, 5, 6, 7, 8
$ RFSTDTC <chr> "2026-01-05", "2026-01-07", "2026-01-10", "2026-01-12", "2026-…
$ RFENDTC <chr> "2026-03-15", "2026-03-20", "2026-03-18", "2026-03-25", "2026-…
$ BRTHDTC <chr> "1965-05-10", "1970-08-21", "1962-02-15", "1975-11-02", "1968-…
$ AGE <dbl> 60, 55, 64, 50, 57, 53, 65, 47
$ SEX <chr> "M", "F", "M", "F", "M", "F", "M", "F"
$ RACE <chr> "WHITE", "ASIAN", "BLACK", "ASIAN", "WHITE", "BLACK", "ASIAN",…
$ ARMCD <chr> "TRT", "TRT", "PBO", "PBO", "TRT", "TRT", "PBO", "PBO"
$ ARM <chr> "Treatment", "Treatment", "Placebo", "Placebo", "Treatment", "…
$ COUNTRY <chr> "USA", "INDIA", "USA", "INDIA", "UK", "CANADA", "INDIA", "USA"
SDTM DM Dataset
The input SDTM DM dataset contains one record per subject.
Example structure:
head(dm)# A tibble: 6 × 13
STUDYID DOMAIN USUBJID SUBJID RFSTDTC RFENDTC BRTHDTC AGE SEX RACE ARMCD
<chr> <chr> <chr> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> <chr>
1 ONCO001 DM ONCO001… 1 2026-0… 2026-0… 1965-0… 60 M WHITE TRT
2 ONCO001 DM ONCO001… 2 2026-0… 2026-0… 1970-0… 55 F ASIAN TRT
3 ONCO001 DM ONCO001… 3 2026-0… 2026-0… 1962-0… 64 M BLACK PBO
4 ONCO001 DM ONCO001… 4 2026-0… 2026-0… 1975-1… 50 F ASIAN PBO
5 ONCO001 DM ONCO001… 5 2026-0… 2026-0… 1968-0… 57 M WHITE TRT
6 ONCO001 DM ONCO001… 6 2026-0… 2026-0… 1972-0… 53 F BLACK TRT
# ℹ 2 more variables: ARM <chr>, COUNTRY <chr>
Create Initial ADSL Dataset
Since ADSL contains one record per subject, we begin by selecting the subject-level variables from the SDTM DM dataset that will form the basis of the analysis dataset.
adsl <- dm %>%
select(
STUDYID,
USUBJID,
SUBJID,
AGE,
SEX,
RACE,
ARMCD,
ARM,
COUNTRY,
RFSTDTC,
RFENDTC
)At this stage, ADSL contains variables directly inherited from SDTM DM.
Derive Treatment Variables
ADaM requires treatment variables for statistical analysis.
The planned treatment variables are derived from SDTM treatment assignments.
adsl <- adsl %>%
mutate(
TRT01P = ARM,
TRT01PN = case_when(
ARMCD == "TRT" ~ 1,
ARMCD == "PBO" ~ 2
)
)Explanation:
| Variable | Description |
|---|---|
| TRT01P | Planned treatment |
| TRT01PN | Numeric planned treatment code |
Numeric treatment variables are commonly used in statistical analyses, reporting, and model development.
Convert SDTM Dates using admiral
SDTM dates are stored as character variables following ISO 8601 format.
Example:
RFSTDTC = "2026-01-05"
Although SDTM stores dates as ISO 8601 character variables, ADaM commonly represents analysis dates as date variables to support calculations, comparisons, and statistical analyses.
The admiral function derive_vars_dt() performs this conversion.
adsl <- adsl %>%
derive_vars_dt(
dtc = RFSTDTC,
new_vars_prefix = "TRTSDT"
) %>%
rename(TRTSDT = TRTSDTDT)This creates:
TRTSDT
Example:
| Variable | Data Type | Example Value |
|---|---|---|
| RFSTDTC | Character (<chr>) |
"2026-01-05" |
| TRTSDT | Date (<date>) |
2026-01-05 |
Although the displayed values appear the same, the data type has changed. RFSTDTC is stored as a character variable in the SDTM dataset, whereas TRTSDT is stored as a Date variable in the ADaM dataset, making it suitable for date-based analyses and derivations.
The derivation maintains traceability:
SDTM DM.RFSTDTC
|
|
v
ADaM ADSL.TRTSDT
derive_vars_dt() derives the analysis date variable TRTSDTDT, which is then renamed to TRTSDT for simplicity in this example.
Create Population Flags
ADaM datasets commonly contain analysis population flags.
Safety Population
For this example, subjects with a non-missing treatment start date are included in the Safety Population.
adsl <- adsl %>%
mutate(
SAFFL = if_else(
!is.na(TRTSDT),
"Y",
"N"
)
)Intent-to-Treat Population
For this example, subjects with a planned treatment assignment are included in the Intent-to-Treat Population.
adsl <- adsl %>%
mutate(
ITTFL = if_else(
!is.na(ARMCD),
"Y",
"N"
)
)Create Age Group
Categorical analysis variables are often derived in ADaM.
adsl <- adsl %>%
mutate(
AGEGR1 = case_when(
AGE < 60 ~ "<60",
AGE >= 60 ~ ">=60"
)
)View the ADSL Dataset
head(adsl)# A tibble: 6 × 17
STUDYID USUBJID SUBJID AGE SEX RACE ARMCD ARM COUNTRY RFSTDTC RFENDTC
<chr> <chr> <dbl> <dbl> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
1 ONCO001 ONCO001-… 1 60 M WHITE TRT Trea… USA 2026-0… 2026-0…
2 ONCO001 ONCO001-… 2 55 F ASIAN TRT Trea… INDIA 2026-0… 2026-0…
3 ONCO001 ONCO001-… 3 64 M BLACK PBO Plac… USA 2026-0… 2026-0…
4 ONCO001 ONCO001-… 4 50 F ASIAN PBO Plac… INDIA 2026-0… 2026-0…
5 ONCO001 ONCO001-… 5 57 M WHITE TRT Trea… UK 2026-0… 2026-0…
6 ONCO001 ONCO001-… 6 53 F BLACK TRT Trea… CANADA 2026-0… 2026-0…
# ℹ 6 more variables: TRT01P <chr>, TRT01PN <dbl>, TRTSDT <date>, SAFFL <chr>,
# ITTFL <chr>, AGEGR1 <chr>
The resulting ADSL dataset now contains both inherited SDTM variables and newly derived analysis variables required for subject-level statistical analyses.
Review ADSL Dataset
glimpse(adsl)Rows: 8
Columns: 17
$ STUDYID <chr> "ONCO001", "ONCO001", "ONCO001", "ONCO001", "ONCO001", "ONCO00…
$ USUBJID <chr> "ONCO001-SITE001-001", "ONCO001-SITE001-002", "ONCO001-SITE001…
$ SUBJID <dbl> 1, 2, 3, 4, 5, 6, 7, 8
$ AGE <dbl> 60, 55, 64, 50, 57, 53, 65, 47
$ SEX <chr> "M", "F", "M", "F", "M", "F", "M", "F"
$ RACE <chr> "WHITE", "ASIAN", "BLACK", "ASIAN", "WHITE", "BLACK", "ASIAN",…
$ ARMCD <chr> "TRT", "TRT", "PBO", "PBO", "TRT", "TRT", "PBO", "PBO"
$ ARM <chr> "Treatment", "Treatment", "Placebo", "Placebo", "Treatment", "…
$ COUNTRY <chr> "USA", "INDIA", "USA", "INDIA", "UK", "CANADA", "INDIA", "USA"
$ RFSTDTC <chr> "2026-01-05", "2026-01-07", "2026-01-10", "2026-01-12", "2026-…
$ RFENDTC <chr> "2026-03-15", "2026-03-20", "2026-03-18", "2026-03-25", "2026-…
$ TRT01P <chr> "Treatment", "Treatment", "Placebo", "Placebo", "Treatment", "…
$ TRT01PN <dbl> 1, 1, 2, 2, 1, 1, 2, 2
$ TRTSDT <date> 2026-01-05, 2026-01-07, 2026-01-10, 2026-01-12, 2026-01-15, 20…
$ SAFFL <chr> "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y"
$ ITTFL <chr> "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y"
$ AGEGR1 <chr> ">=60", "<60", ">=60", "<60", "<60", "<60", ">=60", "<60"
The derived ADSL dataset now combines subject-level SDTM variables with newly created analysis variables required for downstream statistical analyses.
Subject information
+
Treatment variables
+
Analysis date variables
+
Population flags
+
Derived analysis variables
Validate ADSL
ADSL should contain exactly one record per subject.
Check for duplicate subjects:
adsl %>%
count(USUBJID) %>%
filter(n > 1)# A tibble: 0 × 2
# ℹ 2 variables: USUBJID <chr>, n <int>
Since ADSL contains one record per subject, no duplicate USUBJID values are expected.
ADaM Traceability Concept
One of the key principles of ADaM is traceability.
Example:
| ADSL Variable | Source / Derivation |
|---|---|
| USUBJID | DM.USUBJID |
| AGE | DM.AGE |
| SEX | DM.SEX |
| TRT01P | Derived from DM.ARM |
| TRT01PN | Derived from DM.ARMCD |
| TRTSDT | Derived from DM.RFSTDTC |
| SAFFL | Derived from TRTSDT |
| ITTFL | Derived from ARMCD |
Key Takeaways
In this phase:
- SDTM DM was used as the source dataset
- The admiral package was introduced as a framework for deriving ADaM analysis datasets from SDTM data.
- A subject-level ADaM dataset (ADSL) was created
- Analysis variables required for subject-level statistical analysis were derived, including treatment variables, analysis dates, population flags, and demographic groupings.
- SDTM dates were converted into analysis dates
- Population flags were created
- Traceability from SDTM to ADaM was demonstrated
In the next phase, we’ll use admiral and admiral.test to build additional ADaM datasets such as ADVS and ADAE from the SDTM VS and AE domains.